package chat.bean;

import org.apache.logging.log4j.*;

import chat.*;

/**
 * 특정 채팅방 이름을 관리한다.
 * @author sunabove
 *
 */
public class ChatRoomManager extends WebObject {

	private static final long serialVersionUID = -4265672250810357681L;
	/**
	 * Log4j logger
	 */
	static final Logger logger = LogManager.getLogger(ChatRoomManager.class); 
	
	/**
	 * 채팅방들.
	 * 전역 변수이다.
	 */
	private static final ChatRoomList chatRoomList = new ChatRoomList()  ;

	/**
	 * 채팅방 아이디
	 */
	private int chatRoomId;
	
	/**
	 * 방이름
	 */
	private String chatRoomName ;
	
	/**
	 * 채팅방 개설자
	 */
	private String chatRoomUserName; 
	
	/**
	 * 생성자
	 */
	public ChatRoomManager() {
	}  
	
	public int getChatRoomId() {
		return chatRoomId;
	} 
	public void setChatRoomId(int chatRoomId) {
		this.chatRoomId = chatRoomId;
	} 

	public ChatRoomList getChatRoomList() {
		return chatRoomList;
	}

	public String getChatRoomName() {
		return chatRoomName;
	} 

	public String getChatRoomUserName() {
		return chatRoomUserName;
	}

	public void setChatRoomUserName(String chatRoomUserName) {
		this.chatRoomUserName = this.getConvertKor( chatRoomUserName );
		
	}

	public void setChatRoomName(String roomName) { 
		this.chatRoomName = this.getConvertKor( roomName ); 
	}

	public ChatRoom getChatRoom() {
		ChatRoom chatRoom = null; 
		
		if( this.chatRoomName != null ) {
			chatRoom = ChatRoomManager.chatRoomList.getChatRoomByName( this.chatRoomName ); 
		} else {  
			chatRoom = ChatRoomManager.chatRoomList.getChatRoomById( this.chatRoomId ); 
		}
		
		if( chatRoom != null ) {
			// 채팅방 개설자 이름이 없으면, 채팅방 개설자의 이름을 설정한다.
			if( this.chatRoomUserName != null && this.chatRoomUserName.trim().length() > 0 ) { 
				String chatRoomUserName = chatRoom.getChatRoomUserName();
				if( chatRoomUserName == null || chatRoomUserName.trim().length() < 1 ) {
					chatRoom.setChatRoomUserName( this.chatRoomUserName );
				}
			}
		}
		
		return chatRoom;
	} 
	/**
	 * 채팅방을 개설한다.
	 * @param chatRoomName 개설할 채팅방 이름
	 */
	public void setCreateChatRoom( String chatRoomName ) {
		// 채팅방제목이 유효하면 설정한다.
		if( chatRoomName != null && chatRoomName.trim().length() > 0 ) { 
			this.chatRoomName =  this.getConvertKor( chatRoomName );
		} 
		 
		this.setCreateChatRoom(); 
		
	}
	
	public void setCreateChatRoom( ) {
		this.getChatRoom(); 
	}
	
	public String getCreateChatRoom() {
		return "";
	}

}
